import unittest
from ChessBoard import ChessBoard
from ChessConsts import ChessConsts
class KingGuardTest(unittest.TestCase):
 
	def setUp(self):
		self.cb=ChessBoardFakeThreatened()

	def testCheckKingWhenNotThreatenedShouldAllowAllMoves(self):
		moves=[0,0]
		posFrom=[0,0]
		piece = self.cb._board[0][0]
		self.cb.threatened=[False]	
		result=self.cb.checkKingGuard(posFrom,moves)
		# Moves provided are the same moves returned from the method
		self.assertEquals(result,moves)
		# Verify that the position from in the board was intact by the call	
		self.assertEquals(piece,self.cb._board[0][0])
	def testCheckKingWhenKingIsThreatenedByAllMovementsShouldReturnNoMoves(self):
		moves=((1,0),(1,1))
		posFrom=[0,0]
		piece = self.cb._board[0][0]
		self.cb.threatened=[True,True,True]
		result=self.cb.checkKingGuard(posFrom,moves)
		self.assertEquals(result,[])		
		self.assertEquals(piece,self.cb._board[0][0])

        def testCheckKingWhenKingIsPartiallyThreatenedByMovementsShouldReturnNonThreatenedMoves(self):
                moves=((1,0),(1,1))
                posFrom=[0,0]
                piece = self.cb._board[0][0]
                self.cb.threatened=[True,True,False]
                result=self.cb.checkKingGuard(posFrom,moves)
                self.assertEquals(result,[(1,1)])
                self.assertEquals(piece,self.cb._board[0][0])


	def tearDown(self):
		pass
class ChessBoardFakeThreatened(ChessBoard):
	threatenedIndex=0
	threatened=[]
	def isThreatened(self,x,y):
		result= self.threatened[self.threatenedIndex]
		self.threatenedIndex+=1
		return result
		

def main():
	unittest.main()

if __name__ == '__main__':
	main()
